<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemVersion from '@/api/system/systemVersion'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  systemVersion.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemVersion.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_system_version',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemVersion.getList,
  recycleApi: systemVersion.getRecycleList,
  add: {
    show: true,
    api: systemVersion.save,
    auth: ['system:version:save']
  },
  edit: {
    show: true,
    api: systemVersion.update,
    auth: ['system:version:update']
  },
  delete: {
    show: true,
    api: systemVersion.deletes,
    auth: ['system:version:delete'],
    realApi: systemVersion.realDeletes,
    realAuth: ['system:version:realDeletes']
  },
  recovery: {
    show: true,
    api: systemVersion.recoverys,
    auth: ['system:version:recovery']
  },
  import: {
    show: true,
    url: 'system/version/import',
    templateUrl: 'system/version/downloadTemplate',
    auth: ['system:version:import']
  },
  export: {
    show: true,
    url: 'system/version/export',
    auth: ['system:version:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "版本号",
    dataIndex: "version",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入版本号"
    }
  },
  {
    title: "是否最新",
    dataIndex: "is_new",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "APP文件",
    dataIndex: "apk_file",
    formType: "upload",
    type: "file",
    multiple: false,
    onlyData: true,
    returnType: "url"
  },
  {
    title: "是否是测试版本",
    dataIndex: "is_dev",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "测试",
          value: "1"
        },
        {
          label: "生产",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "是否苹果",
    dataIndex: "is_ios",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "安卓",
          value: "1"
        },
        {
          label: "IOS",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "更新备注",
    dataIndex: "remark",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: true,
    addDisplay: false,
    editDisplay: false,
    sortable: {
      sortDirections: [
        "ascend",
        "descend"
      ],
      sorter: true
    },
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'system:version' } </script>